package com.farm.quartz.controller;

import com.alibaba.fastjson2.JSONObject;
import com.farm.common.core.controller.BaseController;
import com.farm.common.core.domain.AjaxResult;

import com.farm.quartz.Dao.wuWoInfoDao;

import com.farm.quartz.model.wuWoInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("/enterprise/workshop")
public class woInfoController extends BaseController {
    @Resource
    wuWoInfoDao wuwoinfodao;

    @Resource
    wuPageController wupage;

//    @GetMapping("list")
//    public AjaxResult ALL(){
//        ArrayList<wuWoInfo> a = wuwoinfodao.findAllBy();
////        Iterator<wuLawPer> iterator = a.iterator();
////        while(iterator.hasNext()) {//判断当前“指针”下面是否还有元素
////            System.out.println(iterator.next());//如果指针下面有元素，则移动指针并获取相应位置的元素
////        }
//
//        Map<String,String> map = new HashMap<>();
////        map.put("name",a.getName());
////        JSONObject.toJSONString(map)
//        return AjaxResult.success(a);
//    }


    @PostMapping("selectshop")
    public AjaxResult search(@RequestBody wuWoInfo wuwoinfo){

        return AjaxResult.success(wuwoinfodao.getById(wuwoinfo.getJuanid()));
//        return
//        Map<String,Object> map = new HashMap<>();
//        map.put("id",a.getId());
//        map.put("sex",a.getSex());
//        map.put("name",a.getName());
//        map.put("age",a.getAge());
//       return AjaxResult.success(map);
    }


    @PostMapping("addshop")
    @ResponseBody
    public AjaxResult addById(@RequestBody wuWoInfo wuwoinfo)
    {
        return AjaxResult.success("新增成功",wuwoinfodao.save(wuwoinfo));
    }



    @PostMapping("updateshop")
    @ResponseBody
    public AjaxResult updateById(@RequestBody String json)
    {
        int id = JSONObject.parseObject(json).getIntValue("id");
        String type = JSONObject.parseObject(json).getString("type");
        int count = JSONObject.parseObject(json).getIntValue("count");
        String time = JSONObject.parseObject(json).getString("time");
        int juanid = JSONObject.parseObject(json).getIntValue("juanid");
        System.out.println("=================================================================");
//        wuLawPer wuLawPer = new wuLawPer();
//        wuLawPer.setAge("1");
//        wuLawPer.setName("2");
//        wuLawPer.setSex("3");
//        wuLawPer.setId(10);
//        wulawperdao.save(wuLawPer);
        wuwoinfodao.update(id,type,count,time,juanid);
        return wupage.ALL2(10,10);

    }


    @PostMapping("deleteshop")
    @ResponseBody
    public AjaxResult deleteById(@RequestBody String json)
    {
        int juanid = JSONObject.parseObject(json).getIntValue("juanid");
        System.out.println("=================================================================");
//        wuLawPer wuLawPer = new wuLawPer();
//        wuLawPer.setAge("1");
//        wuLawPer.setName("2");
//        wuLawPer.setSex("3");
//        wuLawPer.setId(10);
//        wulawperdao.save(wuLawPer);
        wuwoinfodao.delete(juanid);
        return wupage.ALL2(10,10);


    }

















}
